package com.atguigui.leetcode;

/**
 * 1750.删除字符串两端相同字符后的最短长度
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/12/28 9:41
 */
public class P1750MinimumLengthOfStringAfterDeletingSimilarEnds {
    public static void main(String[] args) {
        Solution solution = new P1750MinimumLengthOfStringAfterDeletingSimilarEnds().new Solution();
        // TO TEST
    }

    class Solution {
        public int minimumLength(String s) {
            int n = s.length();
            int left = 0, right = n - 1;
            while (left < right && s.charAt(left) == s.charAt(right)) {
                char c = s.charAt(left);
                while (left <= right && s.charAt(left) == c) {
                    left++;
                }
                while (left <= right && s.charAt(right) == c) {
                    right--;
                }
            }
            return right - left + 1;
        }
    }
}
